var a = require("../../../@babel/runtime/helpers/defineProperty"), t = getApp();

Component({
    properties: {
        datas: {
            type: null
        },
        component_id: {
            type: null
        },
        page_id: {
            type: null
        },
        index: {
            type: null
        },
        U_tabcontrol: {
            type: null
        },
        bottomShowBol: {
            type: null
        },
        bottomShowBolIndex: {
            type: null
        },
        isLast: {
            type: null
        },
        store_id: {
            type: null
        }
    },
    data: {
        emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
        clientWidth: "375",
        show_list: [],
        alreadyHandleArray: [],
        language: "",
        showMore: !0,
        arrIndex: 1,
        page: 1,
        total_page: 0,
        isLoadMore: !0,
        allLoaded: !1,
        showList: !1
    },
    lifetimes: {
        attached: function() {
            var a = wx.getStorageSync("langIndex");
            this.setData({
                language: a.en
            }), this.setTime();
        },
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        this.data.datas.content_list.length > 0 && this.data.datas.content_list[0] instanceof Object ? this.setData({
            show_list: this.handle_list(this.data.datas.content_list)
        }) : this.setData({
            show_list: this.data.datas.content_list
        }), this.data.datas.list && (this.setData({
            total_page: this.data.datas.list.last_page,
            page: this.data.datas.list.current_page,
            per_page: this.data.datas.list.per_page,
            alreadyHandleArray: this.data.datas.list.data,
            list: this.data.datas.list.data && this.data.datas.list.data.slice(0, this.data.per_page) || []
        }), this.data.total_page <= this.data.page && this.setData({
            isLoadMore: !1,
            allLoaded: !0
        })), this.data.datas.get_number && this.data.datas.get_number <= this.data.per_page && this.setData({
            isLoadMore: !1,
            allLoaded: !0,
            list: this.data.datas.list.data.slice(0, this.data.datas.get_number)
        }), this.setData({
            clientWidth: wx.getSystemInfoSync().windowWidth
        }), this.setData({
            showList: !0
        });
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        setTime: function() {
            for (var t = new Date().getTime(), e = this.data.datas.list.data || [], s = 0; s < e.length; s++) {
                var i, d = 1e3 * e[s].start_time;
                this.setData((a(i = {}, "datas.list.data[" + s + "].day", "00"), a(i, "datas.list.data[" + s + "].hou", "00"), 
                a(i, "datas.list.data[" + s + "].min", "00"), a(i, "datas.list.data[" + s + "].sec", "00"), 
                i)), t > d ? this.setData(a({}, "datas.list.data[" + s + "].begShow", !0)) : (this._countDown(s, e[s].start_time), 
                this.setData(a({}, "datas.list.data[" + s + "].begShow", !1)));
            }
        },
        tohistoryGroup: function(a) {
            var t = a.target.dataset.id || a.currentTarget.dataset.id;
            wx.navigateTo({
                url: "/packageF/others/historyGroup/historyGroup?group_id=".concat(t)
            });
        },
        handle_list: function(a) {
            var t = [];
            return a && a.map(function(a, e) {
                t[e] = a.value;
            }), t;
        },
        _countDown: function(t, e) {
            var s, i = new Date().getTime(), d = e ? 1e3 * e : 0;
            if (d - i > 0) {
                var o, r = (d - i) / 1e3, n = parseInt(r / 86400), l = parseInt(r % 86400 / 3600), h = parseInt(r % 86400 % 3600 / 60), p = parseInt(r % 86400 % 3600 % 60);
                this.setData((a(o = {}, "datas.list.data[" + t + "].day", this._timeFormat(n)), 
                a(o, "datas.list.data[" + t + "].hou", this._timeFormat(l)), a(o, "datas.list.data[" + t + "].min", this._timeFormat(h)), 
                a(o, "datas.list.data[" + t + "].sec", this._timeFormat(p)), o));
            } else {
                var g;
                this.setData((a(g = {}, "datas.list.data[" + t + "].day", "00"), a(g, "datas.list.data[" + t + "].hou", "00"), 
                a(g, "datas.list.data[" + t + "].min", "00"), a(g, "datas.list.data[" + t + "].sec", "00"), 
                g));
            }
            d - i < 0 ? this.setData((a(s = {}, "datas.list.data[" + t + "].day", "00"), a(s, "datas.list.data[" + t + "].hou", "00"), 
            a(s, "datas.list.data[" + t + "].min", "00"), a(s, "datas.list.data[" + t + "].sec", "00"), 
            s)) : setTimeout(this._countDown.bind(this, t, e), 1e3);
        },
        _timeFormat: function(a) {
            return a < 10 ? "0" + a : a;
        },
        gotoDetail: function(a) {
            var t = a.target.dataset.item || a.currentTarget.dataset.item;
            t.store_id ? wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + t.id + "/" + t.store_id + "&name=group"
            }) : wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + t.id + "&name=group"
            });
        },
        getMoreData: function() {
            var a = this, e = this;
            if (this.data.page >= this.data.total_page) this.setData({
                allLoaded: !0
            }); else {
                e.setData({
                    page: e.data.page + 1
                });
                var s = t.getNetAddresss("home-page.get-decorate-page");
                s += "&page=" + e.data.page, s += "&decorate_id=" + e.data.page_id, s += "&component_id=" + e.data.component_id, 
                this.properties.store_id && (s += "&store_id=".concat(this.properties.store_id)), 
                this.data.U_tabcontrol ? (s += "&component_key=U_tabcontrol", s += "&component_info=" + JSON.stringify({
                    list_key: this.data.index
                })) : s += "&component_key=U_goodsgroup", t._getNetWork({
                    url: s,
                    success: function(t) {
                        var s = t.data;
                        if (1 == s.result) {
                            if (a.data.U_tabcontrol ? e.setData({
                                page: s.data[0].remote_data.list.current_page,
                                alreadyHandleArray: a.data.alreadyHandleArray.concat(s.data[0].remote_data.list.data)
                            }) : e.setData({
                                page: s.data.remote_data.list.current_page,
                                alreadyHandleArray: a.data.alreadyHandleArray.concat(s.data.remote_data.list.data)
                            }), e.setData({
                                "datas.list.data": a.data.alreadyHandleArray,
                                arrIndex: a.data.arrIndex + 1
                            }), !(e.data.page < e.data.total_page)) return void e.setData({
                                allLoaded: !0
                            });
                            e.setData({
                                isLoadMore: !0
                            }), a.data.datas.get_number && a.data.list.length > a.data.datas.get_number && a.setData({
                                isLoadMore: !1,
                                allLoaded: !0,
                                list: a.data.list.slice(0, a.data.datas.get_number)
                            });
                        } else e.setData({
                            page: e.data.page - 1,
                            isLoadMore: !1,
                            allLoaded: !0
                        });
                    },
                    fail: function(a) {}
                });
            }
        }
    },
    observers: {
        bottomShowBol: function(a) {
            this.data.U_tabcontrol ? a && this.data.isLast && 5 != this.data.datas.sort_style.choose_icon && this.data.isLoadMore ? this.getMoreData() : this.data.page >= this.data.total_page && this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length > 0 && this.setData({
                newClassification: this.data.newClassification.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
                arrIndex: this.data.arrIndex + 1
            }) : a && this.data.bottomShowBolIndex == this.data.index && 5 != this.data.datas.sort_style.choose_icon && this.data.isLoadMore ? this.getMoreData() : this.data.page >= this.data.total_page && this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length > 0 && this.setData({
                newClassification: this.data.newClassification.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
                arrIndex: this.data.arrIndex + 1
            });
        }
    }
});